package cn.com.yang.egg;

/**
 * @Desc<动态分派和重写>属于单分派类型
 * @Author 杨亿金
 * @Date 2021/1/15 15:03
 * @CopyRight
 * @Version
 */
public class DynamicDispatch {
    static abstract class Animal{
        protected abstract void sayHello();
    }
    static class Cat extends Animal{
        @Override
        protected void sayHello() {
            System.out.println("I'm cat");
        }
    }
    static class Dog extends Animal{
        @Override
        protected void sayHello() {
            System.out.println("I'm dog");
        }
    }

    public static void main(String[] args) {
        Animal cat = new Cat();
        Animal dog = new Dog();
        cat.sayHello();
        dog.sayHello();
        cat = new Dog();
        cat.sayHello();
    }
}
